﻿using System;
using System.IO;

namespace Predictor
{
    class CleanWordnet
    {
        /// <summary>
        /// Cleans wordnet from words containing invalid characters and multiple reference of a word
        /// Author: Panos
        /// </summary>
        /// <param name="wordnetPath"></param>
		
        public static void Clean(string wordnetPath)
        {
            int counter = 0;
            StreamReader input = File.OpenText(wordnetPath);
            StreamWriter output = new StreamWriter(File.Open(Predictor.cleanWordnetPath, FileMode.Create));

            string line;
            string previous = "";

            while ((line = input.ReadLine()) != null)
            {
                if (ValidWord(line) == true && line.ToLower() != previous)
                {
                    output.WriteLine(line.ToLower());
                    counter++;
                }
                previous = line.ToLower();
            }

            Console.WriteLine("{0} words cleaned", counter);
			
			input.Close();
			output.Close();
        }

        static bool ValidWord(string word)
        {
            if (word.Contains("0"))
                return false;
            if (word.Contains("1"))
                return false;
            if (word.Contains("2"))
                return false;
            if (word.Contains("3"))
                return false;
            if (word.Contains("4"))
                return false;
            if (word.Contains("5"))
                return false;
            if (word.Contains("6"))
                return false;
            if (word.Contains("7"))
                return false;
            if (word.Contains("8"))
                return false;
            if (word.Contains("9"))
                return false;
            if (word.Contains("'"))
                return false;
            if (word.Contains("."))
                return false;
            if (word.Contains("-"))
                return false;
            if (word.Contains("_"))
                return false;
            if (word.Contains("/"))
                return false;
            if (word.Contains("("))
                return false;
            if (word.Contains(")"))
                return false;
            return true;
        }

    }
}
